<?php
/**
 * 兼容第三方插件补丁文件
 * @appapi 兼容重整
 * jyopen_c 访问目录，jyopen_a 访问文件
 */
defined('BY_JYA') or exit('error');
define('ACCOUNT_SUBSCRIPTION', 1);
define('ACCOUNT_SUBSCRIPTION_VERIFY', 3);
define('ACCOUNT_SERVICE', 2);
define('ACCOUNT_SERVICE_VERIFY', 4);
define('ACCOUNT_TYPE_OFFCIAL_NORMAL', 1);
define('ACCOUNT_TYPE_OFFCIAL_AUTH', 3);
define('ACCOUNT_TYPE_APP_NORMAL', 4);
define('ACCOUNT_OAUTH_LOGIN', 3);
define('ACCOUNT_NORMAL_LOGIN', 1);
define('ACCOUNT_OPERATE_ONLINE', 1);
define('ACCOUNT_OPERATE_MANAGER', 2);
define('ACCOUNT_OPERATE_CLERK', 3);
define('ATTACH_FTP', 1);
define('ATTACH_OSS', 2);
define('ATTACH_QINIU', 3);
define('ATTACH_COS', 4);
define('COUPON_TYPE_DISCOUNT', '1');
define('COUPON_TYPE_CASH', '2');
define('COUPON_TYPE_GROUPON', '3');
define('COUPON_TYPE_GIFT', '4');
define('COUPON_TYPE_GENERAL', '5');
define('COUPON_TYPE_MEMBER', '6');
define('COUPON_TYPE_SCENIC', '7');
define('COUPON_TYPE_MOVIE', '8');
define('COUPON_TYPE_BOARDINGPASS', '9');
define('COUPON_TYPE_MEETING', '10');
define('COUPON_TYPE_BUS', '11');
define('SYSTEM_COUPON', 1);
define('WEIXIN_ROOT', 'https://mp.weixin.qq.com');
define('WECHAT_COUPON', 2);
define('REGULAR_EMAIL', '/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i');
define('REGULAR_MOBILE', '/1\d{10}/');
define('REGULAR_USERNAME', '/^[\x{4e00}-\x{9fa5}a-z\d_\.]{3,15}$/iu');
define('TEMPLATE_DISPLAY', 0);
define('TEMPLATE_FETCH', 1);
define('TEMPLATE_INCLUDEPATH', 2);
function checklogin() {
    model('core/core')->checklogin();
    return true;
}
function wurl($access, $params = array()) {
    list($jy_c, $action, $do) = explode('/', $access);
    $url = './index.php?';
    $url.= 'action=module&';
    if (!empty($jyopen_c)) {
        $url.= "c={$jyopen_c}&";
    }
    if (!empty($action)) {
        $url.= "a={$action}&";
    }
    if (!empty($do)) {
        $url.= "do={$do}&";
    }
    if (!empty($params)) {
        $queryString = http_build_query($params, '', '&');
        $url.= $queryString;
    }
    return $url;
}
function load() {
    static $loader;
    if (empty($loader)) {
        $loader = new Loader();
    }
    return $loader;
}
class Loader {
    private $cache = array();
	private $singletonObject = array();
	private $loadTypeMap = array(
		'func' => '/api/open_jyapi/function/%s.php',
		'model' => '/api/open_jyapi/model/%s.php',
		'classs' => '/api/open_jyapi/class/%s.php',
		'table' => '/api/open_jyapi/table/%s.php',
		'web' => '/api/web/%s.php',
		'app' => '/api/app/%s.php',
	);
	public function __construct() {
		$this->registerAutoload();
	}
	public function registerAutoload() {
		spl_autoload_register(array($this, 'autoload'));
	}
	public function autoload($class) {
		return true;
	}

	public function __call($type, $params) {
		global $_W;
		$name = $cachekey = array_shift($params);

		if (!empty($this->cache[$type]) && isset($this->cache[$type][$cachekey])) {
			return true;
		}
		if (empty($this->loadTypeMap[$type])) {
			return true;
		}
		$file = sprintf($this->loadTypeMap[$type], $name);
		if (file_exists(IA_ROOT . $file)) {
			include IA_ROOT . $file;
			$this->cache[$type][$cachekey] = true;
		}
		return true;
	}
	public function singleton($name) {
		if (isset($this->singletonObject[$name])) {
			return $this->singletonObject[$name];
		}
		$this->singletonObject[$name] = $this->object($name);
		return $this->singletonObject[$name];
	}
	public function object($name) {
		$this->classs(strtolower($name));
		if (class_exists($name)) {
			return new $name();
		} else {
			return false;
		}
	}
}
function table($name) {
    static $table;
    if (empty($table)) {
        $table = new Table($name);
    }
    return $table;
}
class Table{
	public function __call($name='',$take='') {
		return array();
	}
}
function referer($referer = '') {
    global $_RQ, $_AR;
    $res=model('core/tools')->referer($referer);
    return $res;
}
function cutstr($string, $length, $havedot = false, $charset = '') {
    global $_AR;
    $string=model('core/tools')->cutstr($string, $length, $havedot, $charset);
    return $string;
}
function istrlen($string, $charset = '') {
    global $_AR;
    $string=model('core/tools')->istrlen($string,$charset);
    return $string;
}
function range_limit($num = 0, $downline = '', $upline = '', $returnNear = true) {
     $res=model('core/tools')->istrlen($num, $downline, $upline, $returnNear);
	 return $string;
}
function murl($access, $params = array(), $noredirect = true, $addhost = false) {
    global $_AR;
    list($jyopen_c, $action, $do) = explode('/', $access);
    if (!empty($addhost)) {
        $url = get_account_url() . 'custom/';
    } else {
        $url = './';
    }
    $str = '';
    $url.= "index.php?i={$_SESSION['uniacid']}{$str}&";
    $url.= 'action=module&';
    if (!empty($jyopen_c)) {
        $url.= "c={$jyopen_c}&";
    }
    if (!empty($action)) {
        $url.= "a={$action}&";
    }
    if (!empty($do)) {
        $url.= "do={$do}&";
    }
    if (!empty($params)) {
        $queryString = http_build_query($params, '', '&');
        $url.= $queryString;
        if ($noredirect === false) {
            $url.= '&wxref=mp.weixin.qq.com#wechat_redirect';
        }
    }
    return $url;
}
function template($filename, $flag = TEMPLATE_DISPLAY) {
    global $_AR;
    $source = ROOT_D . "/api/open_jyapi/template/{$filename}.html";
    $compile = ROOT_D . "/data/tpl/web/{$_AR['template']}/{$filename}.tpl.php";
    if (!is_file($source)) {
        exit("文件不存在：'{$filename}'");
    }
    if (DEVELOP || !is_file($compile) || filemtime($source) > filemtime($compile)) {
        template_compile($source, $compile);
    }
    switch ($flag) {
        case TEMPLATE_DISPLAY:
        default:
            extract($GLOBALS, EXTR_SKIP);
            include $compile;
        break;
        case TEMPLATE_FETCH:
            extract($GLOBALS, EXTR_SKIP);
            ob_flush();
            ob_clean();
            ob_start();
            include $compile;
            $contents = ob_get_contents();
            ob_clean();
            return $contents;
        break;
        case TEMPLATE_INCLUDEPATH:
            return $compile;
        break;
    }
}
function template_compile($from, $to, $inplugin = false) {
    $path = dirname($to);
    if (!is_dir($path)) {
        cfc('files')->mkdirs($path);
    }
    $content = template_parse(file_get_contents($from), $inplugin);
    file_put_contents($to, $content);
}
function template_parse($str, $inplugin = false) {
    $str = preg_replace('/<!--{(.+?)}-->/s', '{$1}', $str);
    $str = preg_replace('/{template\s+(.+?)}/', '<?php (!empty($this) && $this instanceof WeModuleSite || ' . intval($inplugin) . ') ? (include $this->template($1, TEMPLATE_INCLUDEPATH)) : (include template($1, TEMPLATE_INCLUDEPATH));?>', $str);
    $str = preg_replace('/{php\s+(.+?)}/', '<?php $1?>', $str);
    $str = preg_replace('/{if\s+(.+?)}/', '<?php if($1) { ?>', $str);
    $str = preg_replace('/{else}/', '<?php } else { ?>', $str);
    $str = preg_replace('/{else ?if\s+(.+?)}/', '<?php } else if($1) { ?>', $str);
    $str = preg_replace('/{\/if}/', '<?php } ?>', $str);
    $str = preg_replace('/{loop\s+(\S+)\s+(\S+)}/', '<?php if(is_array($1)) { foreach($1 as $2) { ?>', $str);
    $str = preg_replace('/{loop\s+(\S+)\s+(\S+)\s+(\S+)}/', '<?php if(is_array($1)) { foreach($1 as $2 => $3) { ?>', $str);
    $str = preg_replace('/{\/loop}/', '<?php } } ?>', $str);
    $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)}/', '<?php echo $1;?>', $str);
    $str = preg_replace('/{(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\[\]\'\"\$]*)}/', '<?php echo $1;?>', $str);
    $str = preg_replace('/{url\s+(\S+)}/', '<?php echo url($1);?>', $str);
    $str = preg_replace('/{url\s+(\S+)\s+(array\(.+?\))}/', '<?php echo url($1, $2);?>', $str);
    $str = preg_replace('/{media\s+(\S+)}/', '<?php echo tomedia($1);?>', $str);
    $str = preg_replace_callback('/<\?php([^\?]+)\?>/s', "template_addquote", $str);
    $str = preg_replace('/{([A-Z_\x7f-\xff][A-Z0-9_\x7f-\xff]*)}/s', '<?php echo $1;?>', $str);
    $str = str_replace('{##', '{', $str);
    $str = str_replace('##}', '}', $str);
    if (!empty($GLOBALS['_W']['setting']['remote']['type'])) {
        $str = str_replace('</body>', "<script>$(function(){\$('img').attr('onerror', '').on('error', function(){if (!\$(this).data('check-src') && (this.src.indexOf('http://') > -1 || this.src.indexOf('https://') > -1)) {this.src = this.src.indexOf('{$GLOBALS['_W']['attachurl_local']}') == -1 ? this.src.replace('{$GLOBALS['_W']['attachurl_remote']}', '{$GLOBALS['_W']['attachurl_local']}') : this.src.replace('{$GLOBALS['_W']['attachurl_local']}', '{$GLOBALS['_W']['attachurl_remote']}');\$(this).data('check-src', true);}});});</script></body>", $str);
    }
    $str = "<?php defined('BY_JYA') or exit('error');?>" . $str;
    return $str;
}
function template_addquote($matchs) {
    $code = "<?php {$matchs[1]}?>";
    $code = preg_replace('/\[([a-zA-Z0-9_\-\.\x7f-\xff]+)\](?![a-zA-Z0-9_\-\.\x7f-\xff\[\]]*[\'"])/s', "['$1']", $code);
    return str_replace('\\\"', '\"', $code);
}
function message($msg, $redirect = '', $type = '') {
    global $_AR, $_RQ , $_GPC;
    if ($redirect == 'refresh') {
        $redirect = $_AR['script_name'] . '?' . $_SERVER['QUERY_STRING'];
    }
    if ($redirect == 'referer') {
        $redirect = referer();
    }
    if ($redirect == '') {
        $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql')) ? $type : 'info';
    } else {
        $type = in_array($type, array('success', 'error', 'info', 'warning', 'ajax', 'sql')) ? $type : 'success';
    }
	if($_GPC['submit']){
		if ($_AR['isajax'] || !empty($_GET['isajax']) || $type == 'ajax') {
		if($type != 'ajax' && !empty($_RQ['target'])) {
			exit("
<script type=\"text/javascript\">
parent.require(['jquery', 'util'], function($, util){
	var url = ".(!empty($redirect) ? 'parent.location.href' : "''").";
	var modalobj = util.message('".$msg."', '', '".$type."');
	if (url) {
		modalobj.on('hide.bs.modal', function(){\$('.modal').each(function(){if(\$(this).attr('id') != 'modal-message') {\$(this).modal('hide');}});top.location.reload()});
	}
});
</script>");
		} else {
			$vars = array();
			$vars['message'] = $msg;
			$vars['redirect'] = $redirect;
			$vars['type'] = $type;
			exit(json_encode($vars));
		}
		}
	}else{
		exi($msg,$type,$redirect);
	}
}
function pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => '')) {
    global $_AR;
    $pdata = array('tcount' => 0, 'tpage' => 0, 'cindex' => 0, 'findex' => 0, 'pindex' => 0, 'nindex' => 0, 'lindex' => 0, 'options' => '');
    if ($context['ajaxcallback']) {
        $context['isajax'] = true;
    }
    if ($context['callbackfuncname']) {
        $callbackfunc = $context['callbackfuncname'];
    }
    $pdata['tcount'] = $total;
    $pdata['tpage'] = (empty($pageSize) || $pageSize < 0) ? 1 : ceil($total / $pageSize);
    if ($pdata['tpage'] <= 1) {
        return '';
    }
    $cindex = $pageIndex;
    $cindex = min($cindex, $pdata['tpage']);
    $cindex = max($cindex, 1);
    $pdata['cindex'] = $cindex;
    $pdata['findex'] = 1;
    $pdata['pindex'] = $cindex > 1 ? $cindex - 1 : 1;
    $pdata['nindex'] = $cindex < $pdata['tpage'] ? $cindex + 1 : $pdata['tpage'];
    $pdata['lindex'] = $pdata['tpage'];
    if ($context['isajax']) {
        if (empty($url)) {
            $url = $_AR['script_name'] . '?' . http_build_query($_GET);
        }
        $pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['findex'] . '\', this);return false;"' : '');
        $pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['pindex'] . '\', this);return false;"' : '');
        $pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['nindex'] . '\', this);return false;"' : '');
        $pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['lindex'] . '\', this);return false;"' : '');
    } else {
        if ($url) {
            $pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"';
            $pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"';
            $pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"';
            $pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"';
        } else {
            $_GET['page'] = $pdata['findex'];
            $pdata['faa'] = 'href="' . $_AR['script_name'] . '?' . http_build_query($_GET) . '"';
            $_GET['page'] = $pdata['pindex'];
            $pdata['paa'] = 'href="' . $_AR['script_name'] . '?' . http_build_query($_GET) . '"';
            $_GET['page'] = $pdata['nindex'];
            $pdata['naa'] = 'href="' . $_AR['script_name'] . '?' . http_build_query($_GET) . '"';
            $_GET['page'] = $pdata['lindex'];
            $pdata['laa'] = 'href="' . $_AR['script_name'] . '?' . http_build_query($_GET) . '"';
        }
    }
    $html = '<div><ul class="pagination pagination-centered">';
    if ($pdata['cindex'] > 1) {
        $html.= "<li><a {$pdata['faa']} class=\"pager-nav\">首页</a></li>";
        $html.= "<li><a {$pdata['paa']} class=\"pager-nav\">&laquo;上一页</a></li>";
    }
    if (!$context['before'] && $context['before'] != 0) {
        $context['before'] = 5;
    }
    if (!$context['after'] && $context['after'] != 0) {
        $context['after'] = 4;
    }
    if ($context['after'] != 0 && $context['before'] != 0) {
        $range = array();
        $range['start'] = max(1, $pdata['cindex'] - $context['before']);
        $range['end'] = min($pdata['tpage'], $pdata['cindex'] + $context['after']);
        if ($range['end'] - $range['start'] < $context['before'] + $context['after']) {
            $range['end'] = min($pdata['tpage'], $range['start'] + $context['before'] + $context['after']);
            $range['start'] = max(1, $range['end'] - $context['before'] - $context['after']);
        }
        for ($i = $range['start'];$i <= $range['end'];$i++) {
            if ($context['isajax']) {
                $aa = 'href="javascript:;" page="' . $i . '" ' . ($callbackfunc ? 'onclick="' . $callbackfunc . '(\'' . $url . '\', \'' . $i . '\', this);return false;"' : '');
            } else {
                if ($url) {
                    $aa = 'href="?' . str_replace('*', $i, $url) . '"';
                } else {
                    $_GET['page'] = $i;
                    $aa = 'href="?' . http_build_query($_GET) . '"';
                }
            }
            $html.= ($i == $pdata['cindex'] ? '<li class="active"><a href="javascript:;">' . $i . '</a></li>' : "<li><a {$aa}>" . $i . '</a></li>');
        }
    }
    if ($pdata['cindex'] < $pdata['tpage']) {
        $html.= "<li><a {$pdata['naa']} class=\"pager-nav\">下一页&raquo;</a></li>";
        $html.= "<li><a {$pdata['laa']} class=\"pager-nav\">尾页</a></li>";
    }
    $html.= '</ul></div>';
    return $html;
}
function token($specialadd = '') {
    global $_AR;
    if (!defined('IN_MOBILE')) {
        return substr(md5($_AR['config']['setting']['authkey'] . $specialadd), 8, 8);
    } else {
        if (!empty($_SESSION['token1'])) {
            $count = count($_SESSION['token1']) - 5;
            asort($_SESSION['token1']);
            foreach ($_SESSION['token1'] as $k => $v) {
                if (TIMESTAMP - $v > 300 || $count > 0) {
                    unset($_SESSION['token1'][$k]);
                    $count--;
                }
            }
        }
        $key = substr(random(20), 0, 4);
        $_SESSION['token1'][$key] = TIMESTAMP;
        return $key;
    }
}
function checksubmit($var = 'submit', $allowget = false) {
    global $_AR, $_RQ, $_GPC, $_W;
	if($_W['ispost']){
		 return TRUE;
	}
    if (empty($_RQ)) {
        $_RQ = $_GPC;
    }
    if (empty($_AR)) {
        $_AR = $_W;
    }
    if (empty($_RQ[$var])) {
        return FALSE;
    }
    if (defined('IN_SYS')) {
        if ($allowget || ((!empty($_W['token']) && $_W['token'] == $_RQ['token']) && (empty($_SERVER['HTTP_REFERER']) || preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])))) {
            return TRUE;
        }
    } else {
        if (empty($_W['isajax']) && empty($_SESSION['token1'][$_RQ['token']])) {
            message('抱歉，表单已经失效请您重新进入提交数据', referer(), 'error');
        } else {
            unset($_SESSION['token1'][$_RQ['token']]);
        }
        return TRUE;
    }
    return FALSE;
}
function array_elements($keys, $src, $default = FALSE) {
    $return = array();
    if (!is_array($keys)) {
        $keys = array($keys);
    }
    foreach ($keys as $key) {
        if (isset($src[$key])) {
            $return[$key] = $src[$key];
        } else {
            $return[$key] = $default;
        }
    }
    return $return;
}
function member_change($data, $mid = '') {
    //参数说明
    /*$data=array(
    'qq'=>'qq号',
    'mobile'=>'手机号码',
    'realname'=>'真实姓名'
    'nickname'=>'昵称',
    'avatar'=>'头像',
    'address'=>'地址',
    'birth'=>'生日',
    'pcd'=>'行政区划'
    );*/
    if (!$mid) {
        if (!$_SESSION['uid']) {
            exi('error:no mid', 'error');
        }
        $mid = $_SESSION['uid'];
    }
    $fields = array('qq', 'mobile', 'realname', 'nickname', 'avatar', 'address', 'birth', 'pcd', 'sex');
    $data = array_fields($fields, $data);
    if ($data['birth'] && is_array($data['birth'])) {
        $data['birth'] = ijson_encode($data['birth']);
    }
    if ($data['pcd'] && is_array($data['pcd'])) {
        $data['pcd'] = ijson_encode($data['pcd']);
    }
    if ($data) {
        pdo_update('core_members', $data, array('id' => $mid, 'uniacid' => $_SESSION['uniacid']));
    }
}
function filter_url($params) {
    global $_AR;
    if (empty($params)) {
        return '';
    }
    $query_arr = array();
    $parse = parse_url($_AR['siteurl']);
    if (!empty($parse['query'])) {
        $query = $parse['query'];
        parse_str($query, $query_arr);
    }
    $params = explode(',', $params);
    foreach ($params as $val) {
        if (!empty($val)) {
            $data = explode(':', $val);
            $query_arr[$data[0]] = trim($data[1]);
        }
    }
    $query_arr['page'] = 1;
    $query = http_build_query($query_arr);
    return './index.php?' . $query;
}
function user_check($params) {
    if (!$params || !is_array($params)) {
        return false;
    }
    if ($params['uid']) {
        $check = pdo_getcolumn('core_users', array('id' => $params['uid']), 'id');
        return $check ? true : false;
    }
    if ($params['username']) {
        $user = pdo_get('core_users', array('name' => $params['username']));
        if (!$user) {
            return false;
        }
        if ($params['password']) {
            return check_password($params['password'], $user['salt'], $user['password']);
        }
        return true;
    }
    return false;
}
function user_update($member) {
    if (!$member['uid']) {
        return error('缺少uid参数！');
    }
    $id = intval($member['uid']);
    if ($member['username']) {
        $member['name'] = $member['username'];
    }
    $update = array_fields(array('name', 'password', 'status', 'salt', 'mobile'), $member);
    if ($update['password']) {
        if (!$update['salt']) {
            $update['salt'] = random(8);
        }
        $update['password'] = get_password($update['password'], $update['salt']);
    }
    pdo_update('core_users', $update, array('id' => $id));
    return true;
}
function user_register($member, $plugin = '') {
    if (!$member['username']) {
        return error('请先设置用户名！');
    }
    $member['name'] = $member['username'];
    $member = array_fields(array('name', 'password', 'status', 'salt', 'mobile'), $member);
    if ($member['password']) {
        if (!$member['salt']) {
            $member['salt'] = random(8);
        }
        $member['password'] = get_password($member['password'], $member['salt']);
    }
    $member['uniacid'] = $_SESSION['uniacid'];
    $member['type'] = 1;
    pdo_insert('core_users', $member);
    $id = pdo_insertid();
    if ($plugin) {
        $permission_id = pdo_getcolumn('core_plugin_permissions', array('plugin' => $plugin, 'action' => ''), 'id');
        if ($permission_id) {
            $permission = array('uid' => $id, 'uniacid' => $_SESSION['uniacid'], 'plugin_actions' => ';' . $permission_id . ';',);
            pdo_insert('core_user_permissions', $permission);
        }
    }
    return $id;
}
function user_single($user) {
    if (is_numeric($user)) {
        $user = array('id' => $user);
    }
    if (!is_array($user)) {
        return false;
    }
    if ($user['username']) {
        $user['name'] = $user['username'];
        unset($user['username']);
    }
    $user = pdo_get('core_users', $user);
    if ($user) {
        $user['username'] = $user['name'];
        return $user;
    }
    return false;
}
function up_file() {
    $js = <<<TPL
	<script>
	function up_file(type,callback){
		var html='<input style="display:none;" type="file" value="">';
		var input=$(html);
		if(type=='image'){
			input.attr('accept','image/*');
		}
		$(document.body).append(input);
		input.change(function(){
			var filename=$(this).val();
			var file=this.files[0];
			var reader=new FileReader();
			reader.onload=function(){
				var data={'filedata':reader.result,'filename':filename,'plugin':'core','action':'tools.file_upload','op':'local'};
				if(type){
					data.type=type;
				}
				var url='../api.php?this=custom&token={$_SESSION['token']}';
				$.ajax({
					url: url, type: "post", dataType: "json", timeout: "10000",
					data: data,success: function (result) {
						if(result.type=='success'){
							if($.isFunction(callback)){
								callback(result.message);
							}else{
								alert('上传成功！回调函数错误！');
							}
							input.remove();
							
						}else{
							var res=JSON.stringify(result);
							alert('上传失败！'+res);
						}
					}
				});
			}
			reader.readAsDataURL(file);
		});
		input.click();
	}
	</script>
TPL;
    return $js;
}
